package com.javaPro.myProject.modules.notice.service.impl;

import com.javaPro.myProject.common.model.AjaxResult;
import com.javaPro.myProject.modules.notice.mapper.QTitleMapper;
import com.javaPro.myProject.modules.notice.model.QTitle;
import com.javaPro.myProject.modules.notice.service.QTitleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (公告)表服务实现类
 *

 */
@Service("qTitleService")
public class QTitleServiceImpl implements QTitleService {
    @Resource
    private QTitleMapper qTitleMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public QTitle queryById(Integer id) {
        return this.qTitleMapper.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param qTitle 筛选条件
     * @return 查询结果
     */
    @Override
    public List<QTitle> queryByPage(QTitle qTitle) {
        List<QTitle> list =  this.qTitleMapper.queryAllByLimit(qTitle);
        for (QTitle title : list) {
//遇到 换行符 \n ， 就另起一行
            title.setContent("<p>" +  title.getContent().replace("\n","</p><p>") + "</p>");
        }
        return list;
    }

    /**
     * 新增数据
     *
     * @param qTitle 实例对象
     * @return 实例对象
     */
    @Override
    public QTitle insert(QTitle qTitle) {
        this.qTitleMapper.insert(qTitle);
        return qTitle;
    }

    /**
     * 修改数据
     *
     * @param qTitle 实例对象
     * @return 实例对象
     */
    @Override
    public AjaxResult update(QTitle qTitle) {
        int update = this.qTitleMapper.update(qTitle);
        return AjaxResult.autoJudge(update);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.qTitleMapper.deleteById(id) > 0;
    }
}
